import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import 'dotenv/config'; // 这行是关键代码
import { CorsOptions } from "@nestjs/common/interfaces/external/cors-options.interface";


async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    // 开启logger
    logger: ["error", "warn", "debug", "verbose", "log"],
  });

  // 静态资源目录
  app.useStaticAssets(join(__dirname, './assests'),{
    // prefix: '/static/', //设置虚拟前缀路径
    // maxAge: 1000 * 60, //设置缓存时间
  });

  const corsOption:CorsOptions = {
    origin: true,
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    allowedHeaders: 'Content-Type, Authorization',
  };
  app.enableCors(corsOption);



  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
